/** @format */

import { resultsModel } from '../../../sdk'
import { CODE_TYPES } from '../../../errorCode'
import { dbFindOne } from '../mongodb'
import { JOIN_DB_NAME } from '../../../db'

export default async function checkToolLimit(context: IContext<IParams>) {
  const { openId } = context
  const { gameId, activityId } = context.data
  if (!gameId) {
    return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `缺少gameId参数`)
  }
  const joinInfo = await dbFindOne<IJoinRecord>(context, JOIN_DB_NAME, { _id: gameId, activityId })

  if (joinInfo?.useTimeToolCount > 0) return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `单局提交道具达到使用限制！`)
}
